import { textVantToa } from '_projectFn/prompt'

// 用于检查相关

function checkDataIsgeted({data, key, callback, checkIntervalTime = 10}){
    if (typeof data != "object") return
    if (data[key] === undefined) {
        setTimeout(() => {
            // console.log('data[key]', data[key])
            checkDataIsgeted(data, key, callback, checkIntervalTime)
        }, checkIntervalTime)
    }else{
        callback(data[key])
    }
}

//封装验证手机号码正则
function checkMobile(element, show = true) {
    if (!(/^1[3|4|5|7|8][0-9]\d{4,8}$/.test(element))) {
        if (show) {
            textVantToa({message: '请填写正确的手机号码'})
        }
        return false
    } 
    return true
}

// 检测对象属性值等于固定值时返回
function checkDataEqualVal ({data, key, callback, val, checkIntervalTime = 10}) {
    // console.log('callback', callback)
    if (typeof data === "object" && key && typeof callback === 'function' && val) {
        if (data[key] === val || (Array.isArray(val) && val.indexOf(data[key]) >= 0)) {
            callback(data[key])
        } else {
            setTimeout(() => {
                checkDataEqualVal({data, key, callback, val, checkIntervalTime})
            }, checkIntervalTime)
        }
    }
}

export { checkDataIsgeted, checkMobile, checkDataEqualVal}